
function ListUtil(context,action,listPath){
	this.context = context;
	this.action = context + action;
	
	this.listPath = context + listPath;
	
	this.objFactory = new ObjectFactory();
}

ListUtil.prototype = {
	isNull:function(obj){
		if("undefined" == obj || null == obj || "" == obj ){
			return true;
		}
		return false;
	},
	onTrMouseOver:function(trObj){
		trObj.style.background='threedface';//threedface
	},
	onTrMouseOut:function(trObj){
		trObj.style.background='';
	},
	onTdClick:function(tdObj){
		tdObj.parentNode.childNodes[0].childNodes[0].checked=true;
	},
	selectAll:function(thisObj){
		var fidArr = document.getElementsByName("fid");
		if(thisObj.checked == true){
			for(var i = 0;i<fidArr.length;i++){
				fidArr[i].checked = true;
			}
		}else{
			for(var i = 0;i<fidArr.length;i++){
				fidArr[i].checked = false;
			}
		}
	},
	getSelectCheckBoxArr:function() {
		var fid = ( arguments[0] == null ? "fid" :arguments[0] );
		var pkArr = document.getElementsByName(fid);
	    var len = pkArr.length;
	    var selectObjArr = new Array();
	    for (var i = 0; i < len; i++) {
	        if (pkArr[i].checked == true) {
	        	selectObjArr[selectObjArr.length] = pkArr[i];
	        }
	    }
	    return selectObjArr;
	},
	checkSelect:function(flag){
		var selectObjArr = this.getSelectCheckBoxArr();
		var len = selectObjArr.length;
		if(flag == "single"){
			if(len != 1){
				alert("请选择单条记录！");
			}
		}else{//more
			if(len < 1){
				alert("你没有选择任何记录！");
				return false;
			}
		}
		return true;
	},
	toAdd:function(width,height,method){
		if(this.isNull(method)) method = "toEdit";
		if(this.isNull(width)) width = 500;
		if(this.isNull(height)) height = 300;
		var url = this.action + "?action=" + method;
		this.objFactory.getWindow(url,width,height,"add");
	},
	toEdit:function(width,height,method){
		if(this.isNull(method)) method = "toEdit";
		if(this.isNull(width)) width = 500;
		if(this.isNull(height)) height = 300;
		
		var fid = "";
		var selectIndex = 0;
		var fidArr = document.getElementsByName("fid");
		for(var i = 0;i<fidArr.length;i++){
			if(fidArr[i].checked){
				fid = fidArr[i].value;
				selectIndex ++;
			}
		}
		if(selectIndex!=1){
			alert("请选择一条记录");
			return false;
		}
		var url = this.action + "?action=" + method + "&fid=" + fid;
		this.objFactory.getWindow(url,width,height,"edit");
	},
	doDelete:function(method){
		if(this.isNull(method)) method = "doDelete";
		if(this.checkSelect() == true){
			var form = document.forms[0];
			form.action = this.action + "?action=" + method;
			form.submit();
		}
	},
	doDeleteAll:function(method){
		if(this.isNull(method)) method = "doDeleteAll";
		var form = document.forms[0];
		form.action = this.action + "?action=" + method;
		form.submit();
	}
}